package service

import (
	"github.com/gin-gonic/gin"
	"monitoring-api/models"
	"monitoring-api/serializer"
)

// UserInfoService 管理用户信息服务
type UserInfoService struct {
}

// Info 获取用户信息
func (service *UserInfoService) Info(c *gin.Context) serializer.Response {
	var user models.User
	userID, _ := c.Get("user_id")
	res := models.MySql.Where("user_id = ?", userID).First(&user)
	if res.Error != nil {
		return serializer.Response{
			Message: "获取用户信息失败",
			Code:    500,
			Error:   res.Error.Error(),
		}
	}
	token := c.GetHeader("authorization")
	return serializer.BuildUserResponse(user, token)
}
